from typing import Union

import numpy as np


def cart_pole_rule(state: Union[np.ndarray, None], act: int):
    if state is None:
        return act, None, False
    if state[2] < 0 and state[3] < 0:
        act = 0
    elif state[2] > 0 and state[3] > 0:
        act = 1
    return act, None, False
